import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
const originalReplace=VueRouter.prototype.replace
// 修改 原型对象中的push方法与replace方法的重写
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {//如果传了成功或失败的回调
    originalPush.call(this, location, resolve, reject)
  } else {
    originalPush.call(this,location, () => {}, () => {})
  }
}
VueRouter.prototype.replace = function (location, resolve, reject) {
    if (resolve && reject) { //如果传了成功或失败的回调
      originalReplace.call(this, location, resolve, reject)
    } else {
      originalReplace.call(this, location, () => {}, () => {})
    }
}
export default new VueRouter({
  routes: [{
      path: '/home',
      component: () => import('@/pages/Home'),
      meta: {
        showFooter: true
      }
    },
    {
      path: '/search/:keyword',
      name: 'search',
      component: () => import('@/pages/Search'),
      meta: {
        showFooter: true
      }
    }, {
      path: '/login',
      component: () => import('@/pages/Login'),
      meta: {
        showFooter: false
      }
    },
    {
      path: '/register',
      component: () => import('@/pages/Register'),
      meta: {
        showFooter: false
      }
    }, {
      path: '/',
      redirect: '/home',
      meta: {
        showFooter: true
      }
    }
  ]
})